Fix Kotlin/JS publish: expect/actual for MetadataKey identifier#218
Merged
Conversation
enro-common targets Kotlin/JS (for non-UI KMP scenarios like a NodeJS
backend), and Kotlin/JS reflection deliberately refuses qualifiedName at
compile time. NavigationKey.MetadataKey.name was using
this::class.qualifiedName from commonMain, which compiled on every
other target but stopped publishToMavenLocal in its tracks with:
e: β¦/NavigationKey.kt:227:25
This reflection API is not supported in Kotlin/JS.
The reflection call is now an internal expect fun metadataKeyName(kClass)
in commonMain, with actuals per source set:
- androidMain / desktopMain / iosMain / wasmJsMain β qualifiedName, with
a simpleName fallback for the defensive case.
- jsMain β simpleName only (with a doc comment explaining the
cross-package collision risk and why the common
`object MyKey : MetadataKey<β¦>` pattern stays safe).
Verified `./gradlew :enro-common:publishToMavenLocal` succeeds on all
five targets, and `:enro-runtime:desktopTest` still green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
./gradlew publishToMavenLocalwas failing with:enro-commontargets Kotlin/JS (so a NodeJS backend can referenceNavigationKeytypes) but the innerMetadataKey.namewas usingthis::class.qualifiedName, which K/JS refuses at compile time. The code happened to compile on every other target so this only surfaced at publish.Fix
Internal
expect fun metadataKeyName(kClass)in commonMain, with actuals per source set:androidMain/desktopMain/iosMain/wasmJsMainqualifiedName(with a defensivesimpleNamefallback)jsMainsimpleNameonly β with a doc comment explaining the cross-package collision risk and why theobject MyKey : MetadataKey<β¦>pattern stays safeVerified
./gradlew :enro-common:publishToMavenLocalβ succeeds across all five targets (was: failing on JS compile)./gradlew :enro-common:compileKotlinJs/compileKotlinDesktop/compileKotlinIosSimulatorArm64/compileKotlinWasmJsβ all green./gradlew :enro-runtime:desktopTestβ full suite still greenTest plan
./gradlew :enro-common:publishToMavenLocalβ JS target compiles and publishes../gradlew publishToMavenLocal(full project) β confirm the original beta-publish-prep run finishes without the K/JS error.~/.m2/repository/dev/enro/enro-common/3.0.0-beta01/β looks normal, includes the JS variant.π€ Generated with Claude Code